package com.tencent.wxcloudrun.vo.response.acti;

import com.tencent.wxcloudrun.domain.TActi;
import com.tencent.wxcloudrun.domain.TActiFill;
import com.tencent.wxcloudrun.domain.TActiReward;
import com.tencent.wxcloudrun.dto.ActiFillReqDTO;
import com.tencent.wxcloudrun.dto.ActiRewardReqDTO;
import com.tencent.wxcloudrun.enums.ActiStatEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @Author ZhaoZiYin
 * @Date 2025/4/22
 * @Description 活动查询请求出参
 */
@Data
@ApiModel(value = "ActiQueryResVo", description = "活动查询请求出参")
public class ActiQueryResVo {

    @ApiModelProperty("活动参选类型 1-上新活动 2-返图活动")
    private Integer actiType;

    @ApiModelProperty("活动状态 1-草稿 2-未开始 3-进行中 4-抽选中 5-已结束")
    private Integer actiStatus;

    @ApiModelProperty("活动入围状态 1-未开始 2进行中 3-已结束")
    private Integer actiSelectedStatus;

    @ApiModelProperty("活动黑箱状态 1-未开始 2进行中 3-已结束")
    private Integer actiBlackStatus;

    @ApiModelProperty("活动标题")
    private String actiTitle;

    @ApiModelProperty("活动内容")
    private String actiContent;

    @ApiModelProperty("活动图片列表")
    private String actiImgUrlList;

    @ApiModelProperty("活动参选类型 1-手速 2-摇号 3-私养图")
    private Integer actiJoinType;

    @ApiModelProperty("活动日期")
    private Integer actiDate;

    @ApiModelProperty("开始时间")
    private LocalDateTime actiBeginTime;

    @ApiModelProperty("结束时间")
    private LocalDateTime actiEndTime;

    @ApiModelProperty("入围标志 1-入围 0-不入围")
    private Integer selectedFlag;

    @ApiModelProperty("入围参选类型 1-手速 2-摇号 3-私养图")
    private Integer selectedJoinType;

    @ApiModelProperty("入围数量")
    private Integer selectedCount;

    @ApiModelProperty("入围开始时间")
    private LocalDateTime selectedBeginTime;

    @ApiModelProperty("入围结束时间")
    private LocalDateTime selectedEndTime;

    @ApiModelProperty("预售标志 1-预售 0-现货")
    private Integer preSaleFlag;

    @ApiModelProperty("预填标志 1-预填 0-不预填")
    private Integer formFlag;

    @ApiModelProperty("黑箱卡标志 1-允许黑箱卡 0-不允许")
    private Integer blackFlag;

    @ApiModelProperty("黑箱卡数量")
    private Integer blackCount;

    @ApiModelProperty("黑箱卡开始时间")
    private LocalDateTime blackBeginTime;

    @ApiModelProperty("黑箱卡结束时间")
    private LocalDateTime blackEndTime;

    @ApiModelProperty("活动奖励列表")
    private List<ActiRewardReqDTO> rewardList;

    @ApiModelProperty("活动预填列表")
    private List<ActiFillReqDTO> fillList;

    public void build(TActi acti, List<TActiReward> actiRewardList, List<TActiFill> actiFillList) {
        if (Objects.nonNull(acti)) {
            this.setActiType(acti.getActiType());
            this.setActiStatus(acti.getActiStatus());
            this.setActiSelectedStatus(acti.getActiSelectedStatus());
            this.setActiBlackStatus(acti.getActiBlackStatus());
            this.setActiTitle(acti.getActiTitle());
            this.setActiContent(acti.getActiContent());
            this.setActiImgUrlList(acti.getActiImgUrlList());
            this.setActiJoinType(acti.getActiJoinType());
            this.setActiDate(acti.getActiDate());
            this.setActiBeginTime(acti.getActiBeginTime());
            this.setActiEndTime(acti.getActiEndTime());
            this.setSelectedFlag(acti.getSelectedFlag());
            this.setSelectedJoinType(acti.getSelectedJoinType());
            this.setSelectedCount(acti.getSelectedCount());
            this.setSelectedBeginTime(acti.getSelectedBeginTime());
            this.setSelectedEndTime(acti.getSelectedEndTime());
            this.setPreSaleFlag(acti.getPreSaleFlag());
            this.setFormFlag(acti.getFormFlag());
            this.setBlackFlag(acti.getBlackFlag());
            this.setBlackCount(acti.getBlackCount());
            this.setBlackBeginTime(acti.getBlackBeginTime());
            this.setBlackEndTime(acti.getBlackEndTime());
        }
        if (!CollectionUtils.isEmpty(actiRewardList)) {
            List<ActiRewardReqDTO> reqDTOList = getActiRewardReqDTOList(actiRewardList);
            this.setRewardList(reqDTOList);
        }
        if (!CollectionUtils.isEmpty(actiFillList)) {
            List<ActiFillReqDTO> reqDTOList = getActiFillReqDTOList(actiFillList);
            this.setFillList(reqDTOList);
        }
    }

    public List<ActiRewardReqDTO> getActiRewardReqDTOList(List<TActiReward> actiRewardList) {
        List<ActiRewardReqDTO> reqDTOList = new ArrayList<>(actiRewardList.size());
        for (TActiReward actiReward : actiRewardList) {
            ActiRewardReqDTO reqDTO = new ActiRewardReqDTO();
            reqDTO.setRewardType(actiReward.getRewardType());
            reqDTO.setActiRewardLevel(actiReward.getActiRewardLevel());
            reqDTO.setActiRewardType(actiReward.getActiRewardType());
            reqDTO.setActiRewardKey(actiReward.getActiRewardKey());
            reqDTO.setActiRewardCount(actiReward.getActiRewardCount());
            reqDTOList.add(reqDTO);
        }
        return reqDTOList;
    }

    public List<ActiFillReqDTO> getActiFillReqDTOList(List<TActiFill> actiFillList) {
        List<ActiFillReqDTO> reqDTOList = new ArrayList<>(actiFillList.size());
        for (TActiFill actiFill : actiFillList) {
            ActiFillReqDTO reqDTO = new ActiFillReqDTO();
            reqDTO.setFillType(actiFill.getFillType());
            reqDTO.setFillTitle(actiFill.getFillTitle());
            reqDTO.setFillItemList(actiFill.getFillItemList());
            reqDTO.setMustFlag(actiFill.getMustFlag());
            reqDTO.setFillOrder(actiFill.getFillOrder());
            reqDTOList.add(reqDTO);
        }
        return reqDTOList;
    }

}
